<?php
include ('chek.php');
$pid=$input->get('pid');
$row=array(
    'title'=>'',
    'aptor'=>'',
    'contact'=>''
);
//获取当前信息的pid
if($pid){
    $sql="select * from page  WHERE pid='{$pid}'";
    $row=$db->query($sql)->fetch_array(MYSQLI_ASSOC);
}
if($input->get('do')=='chk'){
    $btitle=$input->post('b_title');
    $baptor=$input->post('b_aptor');
    $bcontent=$input->post('b_content');
    if($btitle==''||$baptor==''||$bcontent==''){
        die('不能为空！');
    }
    //修改
    if($pid>0){
        $uptime=time();
        $sql="update page set title='{$btitle}',aptor='{$baptor}',contact='{$bcontent}',uptime='{$uptime}' WHERE pid='{$pid}'";
    }
    //添加;
    else{
        $intime=time();
        $sql="insert into page(`title`,`aptor`,`contact`,`intime`) VALUES ('{$btitle}','{$baptor}','{$bcontent}','{$intime}')";
    }
    $is=$db->query($sql);
    if($is){
        header('location:admin.php');
    }else{
        die('执行失败！');
    }
}

?>
<!DOCTYPE HTML>
<html>
<head>
    <title>添加博客</title>
    <meta charset="utf-8"/>
    <?php include ('../headr.php');?>
</head>
<body>
<?php include ('nav.php');?>
<div class="container">
    <div class="row">
        <h2>添加博客<a href="admin.php" class="pull-right btn btn-default">返回</a></h2>
        <hr/>
        <form class="form-horizontal" action="admin_add.php?do=chk&pid=<?php echo $pid;?>" method="post">
            <div class="form-group">
                <label for="inputEmail3" class="col-sm-2 control-label">标题</label>
                <div class="col-sm-6">
                    <input type="text" name="b_title" class="form-control" id="inputEmail3" placeholder="请输入标题" value="<?php echo $row['title']?>" >
                </div>
            </div>
            <div class="form-group">
                <label for="inputPassword3" class="col-sm-2 control-label">作者</label>
                <div class="col-sm-4">
                    <input type="text" name="b_aptor" class="form-control" id="inputPassword3" placeholder="请输入作者名" value="<?php echo $row['aptor']?>"  >
                </div>
            </div>
            <div class="form-group">
                <label for="inputPassword3" class="col-sm-2 control-label">内容</label>
                <div class="col-sm-6">
                    <textarea name="b_content" style="width: 100%" rows="6"><?php echo $row['contact']?></textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-6">
                    <button type="submit" class="btn btn-default">添加</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>
